<?php use_helper('SEstadisticas') ?>
<?php echo_title('Permisos de Grupo') ?>

<div id="admin_container">
<h1>Permisos del Grupo "<?php echo $group->name ?>"</h1>

  <?php include_partial('grupo/flashes') ?>

  <div id="admin_content">

  <form action="<?php echo url_for('grupo_collection', array('action' => 'batchPermissions')), '?group_id=', $group->getId() ?>" method="post">
    <ul class="admin_actions">
      <li class="admin_batch_actions_choice">
        <select name="batch_action">
          <option value="">Seleccione una acción</option>
          <option value="batchDeletePermissions">Borrar</option>
        </select>
        <?php $form = new BaseForm(); if ($form->isCSRFProtected()): ?>
          <input type="hidden" name="<?php echo $form->getCSRFFieldName() ?>" value="<?php echo $form->getCSRFToken() ?>" />
        <?php endif; ?>
        <input type="submit" value="ok" />
      </li>
      <li class="admin_action_new">
        <?php echo link_to('Agregar', '@grupo_addPermission?id=' . $group->getId()) ?>
      </li>
      <li class="admin_action_show">
        <?php echo link_to('Volver a Grupo', '@grupo_show?id=' . $group->getId()) ?>
      </li>
    </ul>
    <div class="admin_list">
      <?php if ($pager->getNbResults() == 0): ?>
        <p>Sin resultados</p>
      <?php else: ?>
        <table>
          <thead>
            <tr>
              <th id="admin_list_batch_actions">
                <input id="admin_list_batch_checkbox" type="checkbox" onclick="checkAll();">
              </th>
              <th>Nombre</th>
              <th>Descripción</th>
              <th id="admin_list_th_actions">Acciones</th>
            </tr>
          </thead>
          <tfoot>
            <tr>
              <th colspan="5">
                <?php if ($pager->haveToPaginate()) : ?>
                  <?php include_partial('grupo/permissions_pagination', array('pager' => $pager, 'id' => $group->getId())) ?>
                <?php endif; ?>
                <?php echo $pager->getNbResults(), ' ', $pager->getNbResults() == 1 ? 'resultado' : 'resultados' ?>
                <?php if ($pager->haveToPaginate()): ?>
                  <?php printf('(página %s/%s)', $pager->getPage(), $pager->getLastPage()) ?>
                <?php endif; ?>
              </th>
            </tr>
          </tfoot>
          <tbody>
          <?php foreach($pager->getResults() as $i => $permission_group): ?>
            <tr> 
              <td><input class="admin_batch_checkbox" type="checkbox" value="<?php echo($permission_group->permission_id)?>" name="ids[]"></td>
              <td class="admin_text"><?php echo $permission_group->getPermission()->name ?></td>
              <td class="admin_text"><?php echo $permission_group->getPermission()->description ?></td>
              <td>
                <a class="admin_td_action admin_td_action_delete" onclick="deletePermission(<?php echo $permission_group->permission_id ?>)">
                  <span title="Excluir del grupo"></span>
                </a>
              </td>
            </tr>
          <?php endforeach; ?>
          </tbody>
        </table>
      <?php endif; ?>
    </div>

  <script type="text/javascript">
  /* <![CDATA[ */
  function deletePermission(permission_id) {
    var data = {
      message: '¿Desea excluir el permiso seleccionado?',
      url: '<?php echo url_for('@grupo_deletePermission?id=' . $group->getId()) ?>',
      isCSRFProtected: <?php echo $form->isCSRFProtected() ? 'true' : 'false' ?>,
      CSRFFieldName: '<?php echo $form->getCSRFFieldName() ?>',
      CSRFToken: '<?php echo $form->getCSRFToken() ?>',
      fieldName: 'permission_id',
      fieldValue: permission_id
    };

    createDeleteForm(data); //main.js

    return false;
  }

  /* ]]> */
  </script>

  </form>
  </div>
</div>
